package com.rx.mgt.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public  class DateUtil {
    public static String nowTimeString(Date date){
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dataStr = sf.format(date);
        return dataStr;
    }

	/**
	 * 获取当前时间
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String nowTimeString(){
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dataStr = sf.format(new Date());
		return dataStr;
	}

	/**
	 * 获取当前时间
	 * @return yyyy-MM-dd
	 */
	public static String nowDateString(){
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		String dataStr = sf.format(new Date());
		return dataStr;
	}
	/**
	 * 获取当前时间
	 * @return yyyy/MM/dd
	 */
	public static String parseDate(String date){
		try{
			SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd");
			Date dt = sf.parse(date);//.format(date);
			String newDate = sf.format(dt);
			return newDate;
		}catch(Exception e){
			e.printStackTrace();
			return date;
		}
	}
	public static Date getYearFirst(int year){  
        Calendar calendar = Calendar.getInstance();  
        calendar.clear();  
        calendar.set(Calendar.YEAR, year);  
        Date currYearFirst = calendar.getTime();  
        return currYearFirst;  
    }   
    /** 
     * 获取某年最后一天日期 
     * @param year 年份 
     * @return Date 
     */  
    public static Date getYearLast(int year){  
        Calendar calendar = Calendar.getInstance();  
        calendar.clear();  
        calendar.set(Calendar.YEAR, year);  
        calendar.roll(Calendar.DAY_OF_YEAR, -1);  
        Date currYearLast = calendar.getTime();  
        return currYearLast;  
    } 
    
    /**
     * 获取当天起始时间.
     *
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String getCurrentDateStartTime(){  
        Calendar todayStart = Calendar.getInstance();  
        todayStart.set(Calendar.HOUR_OF_DAY, 0);  
        todayStart.set(Calendar.MINUTE, 0);  
        todayStart.set(Calendar.SECOND, 0);  
        todayStart.set(Calendar.MILLISECOND, 0);  
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dataStr = sf.format(todayStart.getTime());
        return dataStr;
    }  
    
    /**
     * 获取当天最后时间.
     *
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String getCurrentDateEndTime(){  
        Calendar todayEnd = Calendar.getInstance();  
        todayEnd.set(Calendar.HOUR, 23);  
        todayEnd.set(Calendar.MINUTE, 59);  
        todayEnd.set(Calendar.SECOND, 59);  
        todayEnd.set(Calendar.MILLISECOND, 999); 
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dataStr = sf.format(todayEnd.getTime());
        return dataStr;
    } 
    /**
     * 获取本周第一天.
     *
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String getWeekStartDate(){
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); 
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        Date date = cal.getTime();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dataStr = sf.format(date);
        return dataStr;
        }
    /**
     * 获取本周第一天.
     *
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String getMonthStartDate(){
        Calendar cal = Calendar.getInstance();
        cal = Calendar.getInstance();  
        cal.add(Calendar.MONTH, 0);  
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        Date date = cal.getTime();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dataStr = sf.format(date);
        return dataStr;
        }
    public static void main(String[] args) {
        System.out.println(getCurrentDateStartTime());
    }
    

}
